﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using Domain;
using NUnit.Framework;
using Rhino.Mocks;

namespace UnitTests.Domain
{
    [TestFixture]
    public class AccountTest
    {
        private RepositoryDataContext repository;
        private MockRepository mockRepository;

        [SetUp]
        public void SetUp()
        {
           mockRepository = new MockRepository();
            repository = MockRepository.GenerateStub<RepositoryDataContext>();
            
        }

        [Test]
        public void ShouldReturnBalaceAmountFromAccount()
        {
            double totalDebits = 50;
            double totalCredits = 100;

            Account account = mockRepository.PartialMock<Account>();
            using (mockRepository.Record())
            {
                SetupResult.For(account.Credits).Return(new EntitySet<Transaction>() {new Transaction() {Amount = totalCredits}});
                SetupResult.For(account.Debits).Return(new EntitySet<Transaction>(){new Transaction() {Amount = totalDebits}});
            }
            using (mockRepository.Playback())
            {
                Assert.AreEqual(totalCredits-totalDebits, account.Balance);
            }
        }

        [TearDown]
        public void TearDown()
        {
            mockRepository.VerifyAll();
        }
    }
}
